﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace QuanLyKhachSan
{
    public partial class UC_User_Edit : System.Web.UI.UserControl
    {
        private int UserID = -1;
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {   
                if (this.Request.QueryString["UserID"] != null)
                {
                    UserID = int.Parse(this.Request.QueryString["UserID"].ToString());
                }
                if (!Page.IsPostBack)
                {
                    if (UserID != -1)
                    {
                        User_Load(); 
                    }
                }
            }
            catch (Exception ex)
            {                
                throw ex;
            }
        }
        /// <summary>
        /// User_Load
        /// </summary>
        protected void User_Load()
        {
            try
            {
                UserInfo item = UserBLL.User_GetItem(UserID);

                txUserName.Text = item.UserName;
                txtFullName.Text = item.FullName;
                txtDisplayName.Text = item.DisplayName;
                if (item.IsActived == 1)
                    chkIsActived.Checked = true;
                else
                    chkIsActived.Checked = false;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        protected void cmdOK_Click(object sender, EventArgs e)
        {
            try
            {
                int IsActived = 0;

                if (chkIsActived.Checked)
                    IsActived = 1;
                
                Common com = new Common();
                if (UserID == -1)
                {
                    UserBLL.User_Add(txUserName.Text, com.Encrypt(txtPassWord.Text), txtFullName.Text, txtDisplayName.Text, IsActived, 0, DateTime.Now.ToString("MM/dd/yyyy"));
                }
                else
                {
                            
                    UserBLL.User_Edit(UserID, txUserName.Text, com.Encrypt(txtPassWord.Text), txtFullName.Text, txtDisplayName.Text, IsActived, 0, DateTime.Now.ToString("MM/dd/yyyy"));
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
}
}
